import api from '@/api'
import { useAuthStore, useUserStore } from '@/store/modules/index.js'

export async function getUserInfo(token) {
  const { data } = await api.getUserByToken(token)
  return data
}

export async function login(loginForm) {
  const { data } = await api.login(loginForm)
  const userStore = useUserStore()
  const authStore = useAuthStore()
  authStore.setToken(data)
  userStore.setUser(data)
}

export async function logout() {
  useAuthStore().logout()
}
